<?php
header('content-type:text/html;charset=utf8');
require_once "../../config.php";
require_once "../../functions.php";
//根据id更新分类的id
$id = $_POST['id'];
$connect = connect();
$sql = "update categories set ";
//遍历$_POST数组，把每个键和值拼接到sql语句中
unset($_POST['id']);
foreach ($_POST as $key => $value) {
    $sql .= "{$key}='{$value}',";
}
$sql = substr($sql,0,-1);
$sql .= " where id = '$id'";
// echo $sql;
// die;
$result = mysqli_query($connect,$sql);
$response = ["code"=>0,"msg"=>"操作失败"];
if($result){
    $response["code"] = 1;
    $response["msg"] = "操作成功";
}
header('content-type:application/json;charset=utf8');
echo json_encode($response);
?>